﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;

namespace TSMR01Xml
{
    public partial class LaneInfoUserControl : UserControl
    {
        public LaneInfoUserControl()
        {
            InitializeComponent();
        }
        public LaneInfoUserControl(string laneID, String tollgateID, DateTime passTime, string laneStatus)
        {
            InitializeComponent();
            LaneID = laneID;
            TollgateID = tollgateID;
            PassTime = passTime;
            LaneStatus = laneStatus;

        }
        private string LaneID { get; set; }
        public string TollgateID { get; set; }
        public DateTime PassTime { get; set; }
        public string LaneStatus { get; set; }
        public string RecordID { get; set; }
        public string CamID { get; set; }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sss"></param>
        /// <returns></returns>
        private string Replaceenter(string sss)
        {
            byte[] ssssAscIi = System.Text.ASCIIEncoding.ASCII.GetBytes(sss);
            for (int i = 0; i < ssssAscIi.Length; i++)
            {
                if (ssssAscIi[i] == 0x0A)
                {
                    ssssAscIi[i] = 0x20;
                }
            }
            return System.Text.ASCIIEncoding.ASCII.GetString(ssssAscIi).Trim();
        }


        private void LaneInfoUserControl_Load(object sender, EventArgs e)
        {
            this.LaneIDLab.Text = $"车道:{Replaceenter(LaneID).ToString()}";
            this.TollgateIDLab.Text = $"卡口编号:{ TollgateID}";
            this.PassTimeLab.Text = $"触发时间:{PassTime.ToString("yyyy/MM/dd HH:mm:ss:fff")}";
            this.RecordIDLab.Text = $"记录号:{RecordID}";
            this.CamIDLab.Text = $"卡口相机编号:{CamID}";


        }
        public void setValue(String tollgateID, DateTime passTime, string laneStatus,string recordID,string camID)
        {
            this.TollgateIDLab.Text = $"卡口编号:{ tollgateID}";
            this.PassTimeLab.Text = $"触发时间:{passTime.ToString("yyyy/MM/dd HH:mm:ss:fff")}";
            this.RecordIDLab.Text= $"记录号:{recordID}";
            this.CamIDLab.Text = $"卡口相机编号:{camID}";

            //this.LaneStatusLab.Text = $"LaneStatus:{ laneStatus}";
            if (Convert.ToByte(laneStatus.Trim()) == 0x00)
            {
                this.LaneStatusLab.BackColor = Color.Red;
                Task.Run(() =>
                {
                    Thread.Sleep(400);
                    this.LaneStatusLab.BackColor = Color.Black;
                });
            }
            else
            {
            }
        }
    }
}
